package com.stuManSystem.views;

import com.stuManSystem.base.BaseDao;
import com.stuManSystem.config.AppConstants;
import com.stuManSystem.config.Dao;
import com.stuManSystem.dao.StudentDao;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DeleteView extends JFrame {
    private JPanel jPanelCenter, jPanelSouth;
    private JButton deleteButton,exitButton;
    private JTextField name,sno;

    public DeleteView(){
        init();
    }
    public void init(){
        setTitle(AppConstants.DELETEVIRE_TITLE);
        jPanelCenter = new JPanel();
        jPanelCenter.setLayout(new GridLayout(3,2));
        jPanelCenter.add(new JLabel(AppConstants.STUDENT_NAME));
        name = new JTextField();
        jPanelCenter.add(name);
        jPanelCenter.add(new JLabel(AppConstants.STUDENT_SNO));
        sno=new JTextField();
        jPanelCenter.add(sno);

        jPanelCenter.add(new JLabel("--------------------------------------------"));
        jPanelCenter.add(new JLabel("--------------------------------------------"));

        jPanelSouth = new JPanel(new GridLayout(1,2));
        deleteButton = new JButton(AppConstants.DELETEVIEW_DELETEBUTTON);
        exitButton = new JButton(AppConstants.EXITBUTTON);
        //删除
        deleteButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String uname = name.getText();
                String xuehao = sno.getText();
                ((StudentDao) BaseDao.getAbilityDAO(Dao.StudentDao)).delete(uname,xuehao);

                new MainView();
                dispose();
            }
        });
        exitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //System.out.println("退出");
                dispose();
            }
        });

        jPanelSouth.add(deleteButton);
        jPanelSouth.add(exitButton);

        this.add(jPanelCenter,BorderLayout.CENTER);
        this.add(jPanelSouth,BorderLayout.SOUTH);


        //设置出现的位置和大小
        this.setBounds(450, 250, 375, 140);
        //窗体对象，默认是不可见的。通过设置setVisible，使其可见。
        this.setVisible(true);
        //拒绝改变窗体大小
        this.setResizable(false);
        //设置关闭窗体时的运行效果，DISPOSE_ON_CLOSE：关闭
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }

    public static void main(String[] args) {

        new DeleteView();
    }
}
